<?php
namespace app\index\controller;

use app\console\model\Wechat;
use app\index\model\News;
use app\console\model\Activity;

class Index extends Home
{
    public function index()
    {
    	$title = '首页';

        $wechat_list = $this->get_wechat();
        $news_list = $this->get_news();
    	$activity_list = $this->get_activity();
    	// dump($activity_list);exit;
    	
        return view('index', compact('title', 'wechat_list', 'news_list', 'activity_list'));
    }

    //小程序案例
    public function get_wechat()
    {
    	$list = Wechat::where('status', 1)->order('sort asc')->select();

    	return $list;
    }

    //集团动态 $limit 显示的条数
    public function get_news($limit = 6)
    {
        $map = array(
            'n.status' => 1,
            'n.is_show' => 1
        );
        $list = News::alias('n')
            ->where($map)
            ->join('jk_news_type t', 'n.type_id = t.id', 'LEFT')
            ->field('n.id, n.title, n.descs, n.create_at, t.name')
            ->order('n.is_show desc')
            ->limit($limit)
            ->select();

        return $list;
    }

    //员工活动 $limit 显示的条数
    public function get_activity($limit=3)
    {

        $list = Activity::where('status', 1)->order('create_at desc')->field('id, pic, title, create_at')->limit($limit)->select();

        return $list;
    }
}
